Fix Java reformatter for empty records and nested lambdas#9421
Open
neilcsmith-net wants to merge 2 commits into
Open
Fix Java reformatter for empty records and nested lambdas#9421neilcsmith-net wants to merge 2 commits into
neilcsmith-net wants to merge 2 commits into
Conversation
Special case reformatting of empty body records without whitespace
(eg. record Foo(int x) {} ) to not insert lines and keep body as is.
The behaviour is only changed for default same-line brace handling.
Fix continuation indenting with nested lambdas being the same by not specifying a specific indent. This already works correctly when wrapAfterLambdaArrow is set. This fixes the default behaviour.
dbalek
approved these changes
Jun 2, 2026
Contributor
dbalek
left a comment
There was a problem hiding this comment.
Looks reasonable. Thanks.
Contributor
Member
Author
|
Thanks @matthiasblaesing Yes, as I said, the other modes are somewhat broken already. This should be the same behaviour as recent releases? I've tried not to touch them for now. If it's not a regression I would prefer to consider as a follow up issue. There's a bit more to think about what to do with them if they're empty (new line may be odd for that), and we need some tests for those other modes. |
Contributor
|
@neilcsmith-net a sorry I overlooked that remark. And yes, the brokenness is identical before and after the change, so ignore that part of my comment. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Fixes for two niggles in the reformatter - empty record bodies and nested lambda continuation indents.
Empty records
Where a record has an empty body with no whitespace -
Stop the reformatter turning this into -
This change keeps the original code intact while reformatting all non-empty bodies as before. The change only affects the default same-line brace placement. The other modes are somewhat broken with records already.
NB. The
classLeftBracePlacementmethod is removed and the code added to the record handling. Despite its name, this isn't used for non-record classes anyway, and while the intention might have been to allow code reuse, the method isn't correct for this.Nested lambda continuations
Where code has nested lambdas, such as -
Stop the reformatter from flattening the continuation indents -
This behaviour is already correct if
wrapAfterLambdaArrowis set, but not in the default case.